﻿@model IEnumerable<Kooboo.CMS.Content.Models.Repository>
@{
    ViewBag.Title = "Content databases".Localize();
    Layout = "~/Views/Shared/Site.cshtml";
}

@section Sidebar{
    @Html.Partial("_SidebarTopSearch")
    <nav class="container block menu">
        @Html.Partial("Menu", Kooboo.Web.Mvc.Menu.MenuFactory.BuildMenu(ViewContext.Controller.ControllerContext, "AreasMenu"))
    </nav>
}
@section Panel{
    <ul class="panel">
        <li>
            <a href="@Url.Action("Create", "Repository", new { @return = ViewContext.HttpContext.Request.RawUrl })">
                @Html.IconImage("add") @("Create".Localize())</a>
        </li>
        <li>
            <a href="@Url.Action("Import", "Repository", new { @return = ViewContext.HttpContext.Request.RawUrl })">
                @Html.IconImage("import")
                @("Import".Localize())</a>
        </li>

        <li>
            <a href="@Url.Action("Guide", "Repository", new RouteValueDictionary(new { @return = ViewContext.HttpContext.Request.RawUrl }))" data-show-on-check="Single" data-command-type="Redirect">
                @Html.IconImage("setting")
                @("Manage".Localize())
            </a>
        </li>

        <li>
            <a href="@Url.Action("Export", "Repository", new RouteValueDictionary(new { @return = ViewContext.HttpContext.Request.RawUrl }))" data-show-on-check="Single" data-command-type="Download">
                @Html.IconImage("export")
                @("Export".Localize())
            </a>
        </li>
        <li>
            <a href="@Url.Action("Delete", "Repository", new RouteValueDictionary(new { @return = ViewContext.HttpContext.Request.RawUrl }))" data-show-on-check="Any" data-command-type="AjaxPost" data-show-on-selector=".notused"
                data-confirm="@("Are you sure you want to delete the content database?".Localize())">
                @Html.IconImage("delete")
                @("Delete".Localize())
            </a>
        </li>
        @foreach (var group in Kooboo.CMS.Sites.Extension.UI.TopToolbar.ToolbarButtons.GetToolbarButtons(ViewContext.RequestContext))
        {
            @Html.Partial("_ToolbarGroupButtons", group)
        }
    </ul>
}


@if (Model.Count() == 0)
{
    <div class="topbar">
        <h1 class="title">@ViewBag.Title</h1>
    </div>
    <div class="block fixed">
        <div class="sitemap-panel clearfix">
            <div class="blank">
                <p>
                    @("You do not have any content database yet, click the button below to create a content database.".Localize())
                </p>
                @Html.ActionLink("Create a database", "Create", "Repository", new { @return = ViewContext.HttpContext.Request.RawUrl }, new { @class = "button" })
            </div>
        </div>
    </div>
}
else
{	
    <div class="topbar">
        <h1 class="title">@ViewBag.Title</h1>
    </div>
    <div class="block fixed" id="database_list">
        @foreach (var item in Model)
        { 
            @Html.Partial("_DatabaseNode", item.AsActual())          
        }
    </div>
}

<script>
    $(function () {
        var $database_list = $('#database_list').find('.database');
        var $check_relateds = $('[data-show-on-check]');
        var selector = 'input:radio.select:checked';
        function reset() {
            $database_list.reset_check_relateds({ check_relateds: $check_relateds, selector: selector, itemTag: 'div.content-block-header' });
        }
        function clear() {
            $database_list.removeClass('checked');
            $database_list.find('input:radio.select').attr('checked', false);
            reset();
        }
        reset();
        $database_list.on('click', function (e) {
            var $self = $(this);
            clear();
            $self.addClass('checked');
            $self.find('input:radio.select').attr('checked', true);
            reset();
            e.stopPropagation();
        });
        $database_list.grid();
        $(document).click(function () {
            clear();
        });
    });
</script>
